import { getAreaObj } from '@/utils/util'

export const importConfig = {
	tabSteps: [
		{
			label: '下载模板',
			download: '下载模板',
			active: 1,
			rules: [
				{
					label: '下载最新导入模板。共1个：',
					children: [
						{
							label: '《目标值信息表》',
							link: true,
							url: 'view_lfTargetValue_downloadTemplate',
						},
					],
				},
			],
		},
		{
			label: '导入摸底名单信息',
			description: '',
			uploadTip: '目标值信息表',
			active: 2,
			url: 'view_lfTargetValue_import',
			code: 5003,
			rules: [
				{
					label: '导入规则说明:',
					children: [{ label: '(1)导入模式为“覆盖导入”，待导入的服务对象的信息会覆盖平台已存在的' }],
				},
			],
		},
	],
}

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '120px',
	column: [
		{
			label: '所属区',
			prop: 'areas',
			propName: 'areas_name',
			type: 'AplidAreaSelect',
			regionGrade: 3,
			checkStrictly: false,
			span: 24,
		},
		{
			label: '目标值',
			prop: 'targetValue',
			type: 'number',
			min: 0,
			controlsPosition: 'right',
			span: 24,
		},
		{
			label: '目标值年份',
			prop: 'targetYear',
			type: 'year',
			valueFormat: 'YYYY',
			span: 24,
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '所属区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			regionGrade: 3,
			checkStrictly: false,
			span: 8,
		},
		{
			label: '目标值',
			prop: 'targetValue',
			type: 'number',
			min: 0,
			controlsPosition: 'right',
			span: 8,
		},
		{
			label: '目标值年份',
			prop: 'targetYear',
			type: 'year',
			valueFormat: 'YYYY',
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '所属区', prop: 'areaName' },
		{ label: '目标值', prop: 'targetValue' },
		{
			label: '目标值年份',
			prop: 'targetYear',
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_lfTargetValue_page',
	add: 'view_lfTargetValue_add',
	edit: 'view_lfTargetValue_edit',
	delete: 'view_lfTargetValue_del',
	import: 'view_lfTargetValue_import',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '摸底名单',
	dictcodes: ['COMMON_FLAG'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'targetYear',
	exportMqTopic: '/ning/export/',
	importLabel: '导入',
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(form.areas, '')
			const areasNameObj: any = getAreaObj(form.areas_name, '')
			resolve({
				...form,
				...areasObj,
				...areasNameObj,
				areas: undefined,
				areasName: undefined,
			})
		})
	},
	beforeOnLoadFormate: async (query) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(query.areas, '')
			resolve({
				...query,
				...areasObj,
				areas: undefined,
			})
		})
	},
	onLoadFormate: async (arr) => {
		return new Promise((resolve, reject) => {
			resolve(
				arr.map((item) => {
					const areasObj: any = getAreaObj(item, '', 'set')
					return {
						...item,
						areas: areasObj.areaIds,
						areas_name: areasObj.names,
					}
				})
			)
		})
	},
	dialogConfig: {
		width: '55%',
	},
	searchConfig,
	formConfig,
	detailConfig: formConfig,
	tableConfig,
	importConfig,
}
